<?php

namespace YmPhp\Admin\Http\Controllers\Business;

use YmPhp\Admin\Models\Business\BusinessActivity;
use YmPhp\Admin\Form;
use YmPhp\Admin\Grid;
use YmPhp\Admin\Models\Business\BusinessCategory;
use YmPhp\Admin\Models\Business\BusinessList;
use YmPhp\Admin\Models\District;
use YmPhp\Admin\Layout\Content;
use YmPhp\Admin\Show;
use YmPhp\Admin\Http\Controllers\AdminController;
use YmPhp\Admin\Widgets\InfoList;

class BusinessActivityController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new BusinessActivity(), function (Grid $grid) {
            $grid->model()->orderBy('sort', 'desc');
            $grid->column('id')->sortable();
            //$grid->column('displayorder');
            $grid->column('album')->image('', 50, 50);
            $grid->column('uid');
            $grid->column('title');
            $grid->column('shid')->display(function ($value) {
                $business = (new BusinessList())->getDetails($value);
                $hangye_id1 = (new BusinessCategory())->getDetail($business->hangye_id1);
                $hangye_id2 = (new BusinessCategory())->getDetail($business->hangye_id2);
                $businessData = "<div style='display: flex'> <img data-action='preview-img' src='{$business->logo}' style='width: 80px;height: 80px;border-radius: 5px'><div style='margin-left: 10px;'>";
                $businessData .= '<span style="height: 28px;line-height: 28px;">' . $business->name . '</span><br>';
                $businessData .= '<span style="height: 28px;line-height: 28px;">' . $hangye_id1->name . ' / ' . $hangye_id2->name . '</span><br>';
                $businessData .= '<span style="height: 28px;line-height: 28px;">' . $business->addr . '</span><br>';
                $businessData .= '</div>';
                return $businessData;
            });
            $grid->column('timeuses');
            $grid->column('sellnum');
            $grid->column('allmax');
            $grid->column('stock');
            $grid->column('start_at')->display(function ($value) {
                $data = "<span>开始时间：$this->start_at</span><br><span>结束时间：$this->end_at</span>";
                return $data;
            });
            $grid->column('status')->select([0 => '待审核', 1 => '上架中', 2 => '已下架']);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->disableEditButton();
            $grid->disableCreateButton();
            $grid->disableViewButton();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail( $id)
    {

        return Show::make($id, new BusinessActivity(), function (Show $show) {
            $show->field('id');
            $show->field('uid');
            $show->field('title');
            $show->field('shid');
            $show->field('lat');
            $show->field('lng');
            $show->field('province');
            $show->field('city');
            $show->field('district');
            $show->field('stock');
            $show->field('sellnum');
            $show->field('timeuses');
            $show->field('week');
            $show->field('month');
            $show->field('rate');
            $show->field('manmax');
            $show->field('allmax');
            $show->field('maxmoney');
            $show->field('attention');
            $show->field('notice');
            $show->field('content');
            $show->field('album');
            $show->field('status');
            $show->field('srange');
            $show->field('views');
            $show->field('shares');
            $show->field('stid');
            $show->field('autostock');
            $show->field('sort');
            $show->field('lastauto');
            $show->field('lijian');
            $show->field('zktype');
            $show->field('start_at');
            $show->field('end_at');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new BusinessActivity(), function (Form $form) {
            $form->display('id');
            $form->text('uid');
            $form->text('title');
            $form->text('shid');
            $form->text('stock');
            $form->text('sellnum');
            $form->text('timeuses');
            $form->checkbox('week')->options(['1'=>'星期一','2'=>'星期二','3'=>'星期三','4'=>'星期四','5'=>'星期五','6'=>'星期六','7'=>'星期日']);
            $form->list('month')->help('格式：每月x号')->width(3,2);
            $form->text('rate');
            $form->text('manmax');
            $form->text('allmax');
            $form->text('maxmoney');
            $form->text('attention');
            $form->text('notice');
            $form->editor('content');
            $form->image('album')->autoUpload()->uniqueName()->saveFullUrl();
            $form->radio('status')->options(['1' => '上架中', '0' => '待审核','2'=>'已下架']);
            $form->text('srange');
            $form->text('views');
            $form->text('shares');
            $form->text('stid');
            $form->text('autostock');
            $form->text('sort');
            $form->text('lastauto');
            $form->text('lijian');
            $form->text('zktype');
            $form->text('start_at');
            $form->text('end_at');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
